package cn.tqfeiyang.smartadmin.commons.pagination;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * 排序转换器
 *
 * @author tqfeiyang
 * @since 2024/9/10 15:14
 */
public class OrderDirectionConverter implements Converter<String, OrderDirection> {

    @Override
    public OrderDirection convert(String source) {
        if ("a".equalsIgnoreCase(source)
                || "asc".equalsIgnoreCase(source)
                || "ascend".equalsIgnoreCase(source)
                || "ascending".equalsIgnoreCase(source)) {
            return OrderDirection.asc;
        } else if ("d".equalsIgnoreCase(source)
                || "desc".equalsIgnoreCase(source)
                || "descend".equalsIgnoreCase(source)
                || "descending".equalsIgnoreCase(source)) {
            return OrderDirection.desc;
        } else {
            return null;
        }
    }

}
